home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / CHAP13.ZIP / PATRON / PATRON.H < prev    next >
C/C++ Source or Header  |  1993-07-19  |  12KB  |  387 lines

  1. /*
  2.  * PATRON.H
  3.  * Modifications for Chapter 13
  4.  *
  5.  * Single include file that pulls in everything needed for other source
  6.  * files in the application.
  7.  *
  8.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Software Design Engineer
  11.  * Microsoft Systems Developer Relations
  12.  *
  13.  * Internet  :  kraigb@microsoft.com
  14.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  15.  */
  16.  
  17.  
  18. #ifndef _PATRON_H_
  19. #define _PATRON_H_
  20.  
  21. #include <windows.h>
  22.  
  23. #include <ole2.h>
  24. #include <ole2ver.h>
  25. #include <ole2ui.h>
  26. #include <bookguid.h>
  27.  
  28. extern "C"
  29.     {
  30.     #include <commdlg.h>
  31.     #include <print.h>
  32.     }
  33.  
  34. #include <classlib.h>
  35. #include "resource.h"
  36. #include "pages.h"
  37.  
  38.  
  39. //PATRON.CPP:  Frame object that creates a main window
  40.  
  41. class __far CPatronFrame : public CFrame
  42.     {
  43.     //CHAPTER13MOD
  44.     //For access to m_pCL for document creation
  45.     friend class CLinkClassFactory;
  46.     //End CHAPTER13MOD
  47.  
  48.     private:
  49.         BOOL            m_fInitialized;     //OleInitialize worked
  50.  
  51.         //CHAPTER13MOD
  52.         BOOL            m_fEmbedding;       //-Embedding on command line?
  53.         DWORD           m_dwRegCO;          //From CoRegisterClassObject
  54.         LPCLASSFACTORY  m_pIClassFactory;
  55.         //End CHAPTER13MOD
  56.  
  57.     protected:
  58.         //Overridable for creating a CPatronClient
  59.         virtual LPCClient CreateCClient(void);
  60.  
  61.         virtual BOOL      FMessageHook(HWND, UINT, WPARAM, LPARAM, LRESULT FAR *);
  62.         virtual BOOL      FRegisterAllClasses(void);
  63.  
  64.         //CHAPTER13MOD
  65.         virtual BOOL      FPreShowInit(void);
  66.         virtual void      ParseCommandLine(void);
  67.         //End CHAPTER13MOD
  68.  
  69.         virtual UINT      CreateGizmos(void);
  70.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  71.  
  72.     public:
  73.         CPatronFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  74.         virtual ~CPatronFrame(void);
  75.  
  76.         //Overrides
  77.         BOOL FInit(LPFRAMEINIT);
  78.  
  79.         virtual void     UpdateMenus(HMENU, UINT);
  80.         virtual void     UpdateGizmos(void);
  81.  
  82.     };
  83.  
  84.  
  85. typedef CPatronFrame FAR * LPCPatronFrame;
  86.  
  87.  
  88. //CHAPTER13MOD
  89.  
  90. //These are global for simplification of object implementation.
  91. extern ULONG g_cObj;
  92. extern ULONG g_cLock;
  93. extern HWND  g_hWnd;
  94.  
  95. //Type for an object-destroyed callback
  96. typedef void (FAR PASCAL *LPFNDESTROYED)(void);
  97.  
  98. //Function for the object to notify on destruction.
  99. void FAR PASCAL ObjectDestroyed(void);
  100.  
  101.  
  102. //ICLASSF.CPP
  103.  
  104. class __far CLinkClassFactory : public IClassFactory
  105.     {
  106.     protected:
  107.         ULONG           m_cRef;
  108.         LPCPatronFrame  m_pFR;          //For document creation.
  109.  
  110.     public:
  111.         CLinkClassFactory(LPCPatronFrame);
  112.         ~CLinkClassFactory(void);
  113.  
  114.         //IUnknown members
  115.         STDMETHODIMP         QueryInterface(REFIID, LPVOID FAR *);
  116.         STDMETHODIMP_(ULONG) AddRef(void);
  117.         STDMETHODIMP_(ULONG) Release(void);
  118.  
  119.         //IClassFactory members
  120.         STDMETHODIMP         CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *);
  121.         STDMETHODIMP         LockServer(BOOL);
  122.     };
  123.  
  124. typedef CLinkClassFactory FAR * LPCLinkClassFactory;
  125.  
  126. //End CHAPTER13MOD
  127.  
  128.  
  129.  
  130.  
  131. //CLIENT.CPP
  132.  
  133. /*
  134.  * The only reason we have a derived class here is to override
  135.  * CreateCDocument so we can create our own type as well as
  136.  * overriding NewDocument to perform one other piece of work once the
  137.  * document's been created.
  138.  */
  139.  
  140. class __far CPatronClient : public CClient
  141.     {
  142.     protected:
  143.         //Overridable for creating a new CDocument
  144.         virtual LPCDocument CreateCDocument();
  145.  
  146.     public:
  147.         CPatronClient(HINSTANCE);
  148.         virtual ~CPatronClient(void);
  149.     };
  150.  
  151. typedef CPatronClient FAR * LPCPatronClient;
  152.  
  153.  
  154.  
  155. //DOCUMENT.CPP
  156.  
  157. //Constant ID for the pages window that lives in a document window
  158. #define ID_PAGES            723
  159.  
  160. //CHAPTER13MOD
  161. /*
  162.  * To support linking to embeddings, the document needs to have
  163.  * IPersistFile and IOleItemContainer interfaces, so we multiply
  164.  * inherit from IUnknown and provide two interface implementations.
  165.  */
  166.  
  167. class __far CPatronDoc : public CDocument, public IUnknown
  168. //End CHAPTER13MOD
  169.     {
  170.     //These need access to FQueryPasteFromData, FPasteFromData
  171.     friend class CDropTarget;
  172.     friend class CDropSource;
  173.  
  174.     //CHAPTER13MOD
  175.     friend class CImpIPersistFile;
  176.     friend class CImpIOleItemContainer;
  177.     //End CHAPTER13MOD
  178.  
  179.     protected:
  180.         LONG            m_lVer;         //Loaded data version
  181.         LPCPages        m_pPG;          //Pages window in us.
  182.         LPSTORAGE       m_pIStorage;    //Root storage for document.
  183.         BOOL            m_fPrintSetup;  //Enable printer setup if no tenants.
  184.  
  185.         class CDropTarget FAR *m_pDropTarget;   //Registered target.
  186.  
  187.         UINT            m_cfEmbeddedObject;     //Clipboard formats
  188.         UINT            m_cfObjectDescriptor;
  189.         UINT            m_cfLinkSource;
  190.         UINT            m_cfLinkSrcDescriptor;
  191.         BOOL            m_fShowTypes;           //Show Objects active?
  192.  
  193.         //CHAPTER13MOD
  194.         ULONG               m_cRef;
  195.         BOOL                m_fRename;          //Rename on USave?
  196.         DWORD               m_dwRegROT;
  197.         LPPERSISTFILE       m_pIPersistFile;
  198.         LPOLEITEMCONTAINER  m_pIOleItemContainer;
  199.         //End CHAPTER13MOD
  200.  
  201.     protected:
  202.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM, LRESULT FAR *);
  203.         BOOL             FQueryPasteFromData(LPDATAOBJECT, LPFORMATETC, LPTENANTTYPE);
  204.         BOOL             FQueryPasteLinkFromData(LPDATAOBJECT, LPFORMATETC, LPTENANTTYPE);
  205.         BOOL             FPasteFromData(LPDATAOBJECT, LPFORMATETC, TENANTTYPE
  206.                              , LPPATRONOBJECT, DWORD, BOOL);
  207.  
  208.     public:
  209.         CPatronDoc(HINSTANCE);
  210.         virtual ~CPatronDoc(void);
  211.  
  212.         //CHAPTER13MOD
  213.         //We now need our ubiquitous set of IUnknown members.
  214.         STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  215.         STDMETHODIMP_(ULONG) AddRef(void);
  216.         STDMETHODIMP_(ULONG) Release(void);
  217.         //End CHAPTER13MOD
  218.  
  219.         virtual BOOL     FInit(LPDOCUMENTINIT);
  220.         virtual void     Clear(void);
  221.  
  222.         virtual BOOL     FDirtyGet(void);
  223.         virtual void     Delete(void);
  224.         virtual BOOL     FQueryPrinterSetup(void);
  225.         virtual BOOL     FQueryObjectSelected(HMENU);
  226.  
  227.         virtual UINT     ULoad(BOOL, LPSTR);
  228.         virtual UINT     USave(UINT, LPSTR);
  229.  
  230.         virtual BOOL     Print(HWND);
  231.         virtual UINT     PrinterSetup(HWND, BOOL);
  232.  
  233.         virtual BOOL     FClip(HWND, BOOL);
  234.         virtual BOOL     FQueryPaste(void);
  235.         virtual BOOL     FPaste(HWND);
  236.         virtual BOOL     FPasteSpecial(HWND);
  237.         virtual BOOL     FQueryEnableEditLinks(void);
  238.         virtual BOOL     FEditLinks(HWND);
  239.         virtual BOOL     FShowOrQueryObjectTypes(BOOL, BOOL);
  240.  
  241.         virtual UINT     NewPage(void);
  242.         virtual UINT     DeletePage(void);
  243.         virtual UINT     NextPage(void);
  244.         virtual UINT     PreviousPage(void);
  245.         virtual UINT     FirstPage(void);
  246.         virtual UINT     LastPage(void);
  247.         virtual void     Rename(LPSTR);
  248.         virtual BOOL     FInsertObject(HWND);
  249.         virtual void     ActivateObject(UINT);
  250.     };
  251.  
  252. typedef CPatronDoc FAR * LPCPatronDoc;
  253.  
  254.  
  255. //CHAPTER13MOD
  256.  
  257. //IPersistFile implementation for CPatronDoc
  258.  
  259. class __far CImpIPersistFile : public IPersistFile
  260.     {
  261.     protected:
  262.         ULONG               m_cRef;      //Interface reference count.
  263.         LPCPatronDoc        m_pDoc;      //Back pointer to the object.
  264.         LPUNKNOWN           m_punkOuter; //Controlling unknown for delegation.
  265.  
  266.     public:
  267.         CImpIPersistFile(LPCPatronDoc, LPUNKNOWN);
  268.         ~CImpIPersistFile(void);
  269.  
  270.         STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
  271.         STDMETHODIMP_(ULONG) AddRef(void);
  272.         STDMETHODIMP_(ULONG) Release(void);
  273.  
  274.         STDMETHODIMP GetClassID(LPCLSID);
  275.  
  276.         STDMETHODIMP IsDirty(void);
  277.         STDMETHODIMP Load(LPCSTR, DWORD);
  278.         STDMETHO